package com.example.sometestdemo.network

import com.example.jsonktconverter.ktutils.JavaKotlinBridgeUtils
import okhttp3.ResponseBody
import retrofit2.Converter
import retrofit2.Retrofit
import java.lang.reflect.Type

class FastJsonToDataBeanConverterFactory : Converter.Factory() {
    override fun responseBodyConverter(
        type: Type, annotations: Array<Annotation>,
        retrofit: Retrofit
    ): Converter<ResponseBody, *> {
        val clazz = getRawType(type)
        return if (String::class.java == type) {
            Converter { value -> value.toString() }
        } else if (JavaKotlinBridgeUtils.getKClass(clazz).isData) {
            FastJsonToDataBeanConverter(clazz,type)
        } else {
            return Converter { value -> value.toString() }
        }
    }
}